using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.Common;
using Husb.Data;
using Husb.DataUtil;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Caching;

using CentralOffice.File.Data;

using FileTable = CentralOffice.File.Data.FileDataSet.FileDataTable;
using FileRow = CentralOffice.File.Data.FileDataSet.FileRow;


namespace CentralOffice.File.DataAccess
{
    public class FileAdapter : DataAccessAdapter<FileDataSet, FileTable, FileRow>
    {
        public const string GetByTaskIdStoredProc = "Files.Files_SelectFilesByTaskId";
        public FileAdapter()
        {
            this.TableName = "File";

            GetAllStoredProc = "Files.Files_SelectFilesAll";
            InsertStoredProc = "Files.Files_InsertFile";
            UpdateStoredProc = "Files.Files_UpdateFile";
            DeleteStoredProc = "Files.Files_DeleteFile";

            GetByIdStoredProc = "Files.Files_SelectFile";
            GetByNameStoredProc = "";
            GetPagedStoredProc = "Files.Files_SelectFilesPaged";
            GetRowCountStoredProc = "Files.Files_SelectFilesRowCount";

            FindStoredProc = "Files.Files_SelectFilesDynamic";
        }

        protected override void PopulateInsertParameters(Database db, DbCommand cmd)
        {
            db.AddInParameter(cmd, "Id", DbType.Guid, "Id", DataRowVersion.Current);
            db.AddInParameter(cmd, "Name", DbType.AnsiString, "Name", DataRowVersion.Current);
            db.AddInParameter(cmd, "Subtitle", DbType.AnsiString, "Subtitle", DataRowVersion.Current);
            db.AddInParameter(cmd, "FileNumber", DbType.AnsiString, "FileNumber", DataRowVersion.Current);
            db.AddInParameter(cmd, "QueryNumber", DbType.AnsiString, "QueryNumber", DataRowVersion.Current);
            db.AddInParameter(cmd, "Keywords", DbType.AnsiString, "Keywords", DataRowVersion.Current);
            db.AddInParameter(cmd, "Theme", DbType.AnsiString, "Theme", DataRowVersion.Current);
            db.AddInParameter(cmd, "UrgencyPriority", DbType.AnsiString, "UrgencyPriority", DataRowVersion.Current);
            db.AddInParameter(cmd, "Publisher", DbType.AnsiString, "Publisher", DataRowVersion.Current);
            db.AddInParameter(cmd, "SecretLevel", DbType.AnsiString, "SecretLevel", DataRowVersion.Current);
            db.AddInParameter(cmd, "FileCategoryId", DbType.Guid, "FileCategoryId", DataRowVersion.Current);
            db.AddInParameter(cmd, "Remark", DbType.String, "Remark", DataRowVersion.Current);
            db.AddInParameter(cmd, "Attachments", DbType.String, "Attachments", DataRowVersion.Current);
            db.AddInParameter(cmd, "ArchivingTime", DbType.DateTime, "ArchivingTime", DataRowVersion.Current);
            db.AddInParameter(cmd, "ArchivedBy", DbType.AnsiString, "ArchivedBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "DepositIn", DbType.AnsiString, "DepositIn", DataRowVersion.Current);
            db.AddInParameter(cmd, "TaskId", DbType.Guid, "TaskId", DataRowVersion.Current);

            db.AddInParameter(cmd, "IsDeleted", DbType.Boolean, "IsDeleted", DataRowVersion.Current);
            db.AddInParameter(cmd, "IsActive", DbType.Boolean, "IsActive", DataRowVersion.Current);
            db.AddInParameter(cmd, "CreatedTime", DbType.DateTime, "CreatedTime", DataRowVersion.Current);
            db.AddInParameter(cmd, "CreatedBy", DbType.Guid, "CreatedBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "ModifiedTime", DbType.DateTime, "ModifiedTime", DataRowVersion.Current);
            db.AddInParameter(cmd, "LastModifiedBy", DbType.Guid, "LastModifiedBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "Version", DbType.Int32, "Version", DataRowVersion.Current);
            db.AddInParameter(cmd, "Description", DbType.String, "Description", DataRowVersion.Current);
        }

        public FileTable GetByTaskId(Guid taskId)
        {
            List<DatabaseParameter> parameters = new List<DatabaseParameter>();
            parameters.Add(new DatabaseParameter("TaskId", DbType.Guid, taskId));


            return this.GetTable(GetByTaskIdStoredProc, parameters, true, false, null);
        }
    }
}
